DROP TABLE IF EXISTS `tb_flow`;
CREATE TABLE `tb_flow`
(
    `pid`         varchar(36)  NOT NULL COMMENT '流程定义PID',
    `flow_name`   varchar(50)  NOT NULL DEFAULT '' COMMENT '流程定义名称',
    `flow_desc`   varchar(255) NOT NULL DEFAULT '' COMMENT '流程定义描述',
    `creator_id`  varchar(36)  NOT NULL DEFAULT '' COMMENT '创建者ID',
    `editor_id`   varchar(36)  NOT NULL DEFAULT '' COMMENT '更新者ID',
    `create_time` datetime     NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT '创建时间',
    `update_time` datetime     NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT '更新时间',
    PRIMARY KEY (`pid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='流程定义表';

INSERT INTO saasr2.tb_flow (pid, flow_name, flow_desc, creator_id, editor_id, create_time, update_time)
VALUES ('1', '鸿之微项目审批', '鸿之微项目审批', 'system', '', '2021-08-04 10:49:48', '2021-08-10 18:04:44');


DROP TABLE IF EXISTS `tb_flow_instance`;
CREATE TABLE `tb_flow_instance`
(
    `pid`                varchar(36)  NOT NULL COMMENT '流程实例PID',
    `flow_id`            varchar(36)  NOT NULL DEFAULT '' COMMENT '流程定义ID',
    `flow_node_id`       varchar(36)  NOT NULL DEFAULT '' COMMENT '流程节点ID',
    `flow_instance_name` varchar(255) NOT NULL DEFAULT '' COMMENT '流程实例名称',
    `state`              tinyint      NOT NULL DEFAULT '0' COMMENT '流程实例状态，-1，异常终止 ，0-流程进行，1-流程完成，2-流程挂起',
    `submit_user_id`     varchar(36)  NOT NULL DEFAULT '' COMMENT '发起人ID',
    `creator_id`         varchar(36)  NOT NULL DEFAULT '' COMMENT '创建者ID',
    `editor_id`          varchar(36)  NOT NULL DEFAULT '' COMMENT '更新者ID',
    `create_time`        datetime     NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT '创建时间',
    `update_time`        datetime     NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT '更新时间',
    `is_delete`          tinyint      NOT NULL DEFAULT '0' COMMENT '逻辑删除',
    PRIMARY KEY (`pid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='流程实例表';

DROP TABLE IF EXISTS `tb_flow_node`;
CREATE TABLE `tb_flow_node`
(
    `pid`              varchar(36)  NOT NULL COMMENT '流程节点PID',
    `flow_id`          varchar(36)  NOT NULL DEFAULT '' COMMENT '流程定义id',
    `flow_node_name`   varchar(50)  NOT NULL DEFAULT '' COMMENT '节点名称',
    `flow_node_text`   varchar(255) NOT NULL DEFAULT '' COMMENT '显示名称',
    `flow_node_desc`   varchar(255) NOT NULL DEFAULT '' COMMENT '节点描述',
    `flow_node_status` tinyint      NOT NULL COMMENT '-1-结束节点，0-起始节点，1-普通节点',
    `flow_node_style`  varchar(20)  NOT NULL DEFAULT '' COMMENT '节点样式',
    `creator_id`       varchar(36)  NOT NULL DEFAULT '' COMMENT '创建者ID',
    `editor_id`        varchar(36)  NOT NULL DEFAULT '' COMMENT '更新者ID',
    `create_time`      datetime     NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT '创建时间',
    `update_time`      datetime     NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT '更新时间',
    PRIMARY KEY (`pid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='流程节点定义表';

-- ----------------------------
-- Records of tb_flow_node
-- ----------------------------
BEGIN;
INSERT INTO saasr2.tb_flow_node (pid, flow_id, flow_node_name, flow_node_text, flow_node_desc, flow_node_status, flow_node_style, creator_id, editor_id, create_time, update_time)
VALUES ('1001', '1', '待提交', '正在编辑', '用户正在编辑审批信息，等待提交', 0, 'normal', 'system', '', '2021-08-04 10:50:38', '2021-08-10 18:04:45');
INSERT INTO saasr2.tb_flow_node (pid, flow_id, flow_node_name, flow_node_text, flow_node_desc, flow_node_status, flow_node_style, creator_id, editor_id, create_time, update_time)
VALUES ('1002', '1', '审批中', '审批中', '管理员正在审批', 1, 'normal', 'system', '', '2021-08-04 10:50:38', '2021-08-10 18:04:45');
INSERT INTO saasr2.tb_flow_node (pid, flow_id, flow_node_name, flow_node_text, flow_node_desc, flow_node_status, flow_node_style, creator_id, editor_id, create_time, update_time)
VALUES ('1003', '1', '审批回退', '审批回退', '管理员审批回退，用户可以继续编辑', 1, 'refuse ', 'system', '', '2021-08-04 10:50:38', '2021-08-10 18:04:45');
INSERT INTO saasr2.tb_flow_node (pid, flow_id, flow_node_name, flow_node_text, flow_node_desc, flow_node_status, flow_node_style, creator_id, editor_id, create_time, update_time)
VALUES ('1004', '1', '审批通过', '审批通过', '管理员审批通过', -1, 'pass', 'system', '', '2021-08-04 10:50:38', '2021-08-10 18:04:45');
INSERT INTO saasr2.tb_flow_node (pid, flow_id, flow_node_name, flow_node_text, flow_node_desc, flow_node_status, flow_node_style, creator_id, editor_id, create_time, update_time)
VALUES ('1005', '1', '审批拒绝', '审批拒绝', '管理员审批关闭，用户不可以编辑', -1, 'refuse ', 'system', '', '2021-08-04 10:50:38', '2021-08-10 18:04:45');
INSERT INTO saasr2.tb_flow_node (pid, flow_id, flow_node_name, flow_node_text, flow_node_desc, flow_node_status, flow_node_style, creator_id, editor_id, create_time, update_time)
VALUES ('1009', '1', '已关闭', '已关闭', '已关闭', -1, 'close', 'system', 'system', '2021-08-11 00:00:00', '2021-08-11 00:00:00');
INSERT INTO `saasr2`.`tb_flow_process`(`pid`, `flow_id`, `flow_process_name`, `flow_process_alias`, `flow_process_style`, `flow_node_pre_id`, `flow_node_next_id`, `default_comment`, `actions`, `creator_id`, `editor_id`, `create_time`,
                                       `update_time`)
VALUES ('10041101', '1', '导出PDF', '导出PDF', 'export', '1004', '1101', '', '', '', '', '1000-01-01 00:00:00', '1000-01-01 00:00:00');
COMMIT;

DROP TABLE IF EXISTS `tb_flow_process`;
CREATE TABLE `tb_flow_process`
(
    `pid`                varchar(36)   NOT NULL COMMENT '流程处理PID',
    `flow_id`            varchar(36)   NOT NULL DEFAULT '' COMMENT '流程定义id',
    `flow_process_name`  varchar(50)   NOT NULL DEFAULT '' COMMENT '流程处理名称',
    `flow_process_alias` varchar(255)  NOT NULL DEFAULT '' COMMENT '流程处理别名',
    `flow_process_style` varchar(20)   NOT NULL DEFAULT '' COMMENT '流程处理样式',
    `flow_node_pre_id`   varchar(36)   NOT NULL DEFAULT '' COMMENT '前流程节点id',
    `flow_node_next_id`  varchar(36)   NOT NULL DEFAULT '' COMMENT '后流程节点id',
    `default_comment`    varchar(2000) NOT NULL DEFAULT '' COMMENT '默认处理意见',
    `actions`            varchar(255)  NOT NULL DEFAULT '' COMMENT '业务逻辑',
    `creator_id`         varchar(36)   NOT NULL DEFAULT '' COMMENT '创建者ID',
    `editor_id`          varchar(36)   NOT NULL DEFAULT '' COMMENT '更新者ID',
    `create_time`        datetime      NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT '创建时间',
    `update_time`        datetime      NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT '更新时间',
    PRIMARY KEY (`pid`),
    UNIQUE KEY `uniq` (`flow_node_pre_id`, `flow_node_next_id`) USING BTREE COMMENT '前后节点唯一'
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='流程处理定义表';

-- ----------------------------
-- Records of tb_flow_process
-- ----------------------------
BEGIN;
INSERT INTO saasr2.tb_flow_process (pid, flow_id, flow_process_name, flow_process_alias, flow_process_style, flow_node_pre_id, flow_node_next_id, default_comment, actions, creator_id, editor_id, create_time, update_time)
VALUES ('10011001', '1', '编辑', '编辑', 'normal', '1001', '1001', '', '', 'system', 'system', '2021-08-10 18:04:46', '2021-08-10 18:04:46');
INSERT INTO saasr2.tb_flow_process (pid, flow_id, flow_process_name, flow_process_alias, flow_process_style, flow_node_pre_id, flow_node_next_id, default_comment, actions, creator_id, editor_id, create_time, update_time)
VALUES ('10011002', '1', '提交', '提交', 'normal', '1001', '1002', '', 'PROJECT_APPLY_SERVICE_SUBMIT', 'system', 'system', '2021-08-10 18:04:46', '2021-08-10 18:04:46');
INSERT INTO saasr2.tb_flow_process (pid, flow_id, flow_process_name, flow_process_alias, flow_process_style, flow_node_pre_id, flow_node_next_id, default_comment, actions, creator_id, editor_id, create_time, update_time)
VALUES ('10011009', '1', '删除', '删除', 'close', '1001', '1009', '', 'PROJECT_APPLY_SERVICE_REMOVE', 'system', 'system', '2021-08-10 18:04:46', '2021-08-10 18:04:46');
INSERT INTO saasr2.tb_flow_process (pid, flow_id, flow_process_name, flow_process_alias, flow_process_style, flow_node_pre_id, flow_node_next_id, default_comment, actions, creator_id, editor_id, create_time, update_time)
VALUES ('10021003', '1', '回退', '回退', 'refuse', '1002', '1003', '', '', 'system', 'system', '2021-08-10 18:04:46', '2021-08-10 18:04:46');
INSERT INTO saasr2.tb_flow_process (pid, flow_id, flow_process_name, flow_process_alias, flow_process_style, flow_node_pre_id, flow_node_next_id, default_comment, actions, creator_id, editor_id, create_time, update_time)
VALUES ('10021004', '1', '通过', '通过', 'pass', '1002', '1004', '', '', 'system', 'system', '2021-08-10 18:04:46', '2021-08-10 18:04:46');
INSERT INTO saasr2.tb_flow_process (pid, flow_id, flow_process_name, flow_process_alias, flow_process_style, flow_node_pre_id, flow_node_next_id, default_comment, actions, creator_id, editor_id, create_time, update_time)
VALUES ('10021005', '1', '拒绝', '拒绝', 'refuse', '1002', '1005', '', '', 'system', 'system', '2021-08-10 18:04:46', '2021-08-10 18:04:46');
INSERT INTO saasr2.tb_flow_process (pid, flow_id, flow_process_name, flow_process_alias, flow_process_style, flow_node_pre_id, flow_node_next_id, default_comment, actions, creator_id, editor_id, create_time, update_time)
VALUES ('10031002', '1', '提交', '提交', 'normal', '1003', '1002', '', 'PROJECT_APPLY_SERVICE_SUBMIT', 'system', 'system', '2021-08-10 18:04:46', '2021-08-10 18:04:46');
INSERT INTO saasr2.tb_flow_process (pid, flow_id, flow_process_name, flow_process_alias, flow_process_style, flow_node_pre_id, flow_node_next_id, default_comment, actions, creator_id, editor_id, create_time, update_time)
VALUES ('10031003', '1', '编辑', '编辑', 'normal', '1003', '1003', '', '', 'system', 'system', '2021-08-10 18:04:46', '2021-08-10 18:04:46');
INSERT INTO saasr2.tb_flow_process (pid, flow_id, flow_process_name, flow_process_alias, flow_process_style, flow_node_pre_id, flow_node_next_id, default_comment, actions, creator_id, editor_id, create_time, update_time)
VALUES ('10031009', '1', '关闭', '关闭', 'close', '1003', '1009', '', '', 'system', 'system', '2021-08-10 18:04:46', '2021-08-10 18:04:46');
INSERT INTO `saasr2`.`tb_flow_node`(`pid`, `flow_id`, `flow_node_name`, `flow_node_text`, `flow_node_desc`, `flow_node_status`, `flow_node_style`, `creator_id`, `editor_id`, `create_time`, `update_time`)
VALUES ('1101', '1', '导出PDF', '导出PDF', '审批通过，导出PDF', 1, 'export', 'system', 'system', '2021-08-17 00:00:00', '2021-08-17 00:00:00');
COMMIT;

DROP TABLE IF EXISTS `tb_flow_process_permission`;
CREATE TABLE `tb_flow_process_permission`
(
    `pid`             int         NOT NULL AUTO_INCREMENT COMMENT '流程处理权限关联PID',
    `flow_process_id` varchar(36) NOT NULL DEFAULT '' COMMENT '流程处理ID',
    `role_id`         varchar(36) NOT NULL DEFAULT '' COMMENT '角色ID',
    `user_id`         varchar(36) NOT NULL DEFAULT '' COMMENT '用户ID',
    PRIMARY KEY (`pid`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 16
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='流程处理权限关联表';

-- ----------------------------
-- Records of tb_flow_process_permission
-- ----------------------------
BEGIN;
INSERT INTO saasr2.tb_flow_process_permission (flow_process_id, role_id, user_id)
VALUES ('10011001', '', '0');
INSERT INTO saasr2.tb_flow_process_permission (flow_process_id, role_id, user_id)
VALUES ('10011002', '', '0');
INSERT INTO saasr2.tb_flow_process_permission (flow_process_id, role_id, user_id)
VALUES ('10011009', '', '0');
INSERT INTO saasr2.tb_flow_process_permission (flow_process_id, role_id, user_id)
VALUES ('10021003', '', '0000000000000000000');
INSERT INTO saasr2.tb_flow_process_permission (flow_process_id, role_id, user_id)
VALUES ('10021004', '', '0000000000000000000');
INSERT INTO saasr2.tb_flow_process_permission (flow_process_id, role_id, user_id)
VALUES ('10021005', '', '0000000000000000000');
INSERT INTO saasr2.tb_flow_process_permission (flow_process_id, role_id, user_id)
VALUES ('10031002', '', '0');
INSERT INTO saasr2.tb_flow_process_permission (flow_process_id, role_id, user_id)
VALUES ('10031003', '', '0');
INSERT INTO saasr2.tb_flow_process_permission (flow_process_id, role_id, user_id)
VALUES ('10031009', '', '0');
INSERT INTO `saasr2`.`tb_flow_process_permission`(`flow_process_id`, `role_id`, `user_id`)
VALUES ('10041101', '', '0');
COMMIT;

DROP TABLE IF EXISTS `tb_flow_process_record`;
CREATE TABLE `tb_flow_process_record`
(
    `pid`              varchar(36)   NOT NULL COMMENT '流程处理记录PID',
    `flow_instance_id` varchar(36)   NOT NULL DEFAULT '' COMMENT '流程实例ID',
    `flow_process_id`  varchar(36)   NOT NULL DEFAULT '' COMMENT '流程处理ID',
    `step`             int           NOT NULL DEFAULT 0 COMMENT '流程处理序号',
    `approver`         varchar(36)   NOT NULL DEFAULT '' COMMENT '审批人ID',
    `suggestion`       varchar(2000) NOT NULL DEFAULT '' COMMENT '审批意见',
    `creator_id`       varchar(36)   NOT NULL DEFAULT '' COMMENT '创建者ID',
    `editor_id`        varchar(36)   NOT NULL DEFAULT '' COMMENT '更新者ID',
    `create_time`      datetime      NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT '创建时间',
    `update_time`      datetime      NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT '更新时间',
    PRIMARY KEY (`pid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='流程处理记录表';
